import Test.QuickCheck

import CPS

-- 1. any type

prop_CPS :: String -> Bool
prop_CPS str = str == (fromCPS . CPS) (\c -> c str)

-- 2. Tuple

prop_tuple :: (Int, Bool) -> Bool
prop_tuple (i, b) = 
    (i, b) == (fromTupleCPS . TupleCPS) (\k -> k i b)

-- 3. Maybe a

prop_maybe :: String -> Bool
prop_maybe str = 
    Just str == (fromMaybeCPS . MaybeCPS) (\ks kf -> ks str) &&
    (Nothing :: Maybe String) == (fromMaybeCPS . MaybeCPS) (\ks kf -> kf)

-- 4. Either a b

prop_either :: (String, Int) -> Bool
prop_either (str, i) = 
    (Left str :: Either String Int) == (fromEitherCPS . EitherCPS) (\kl kr -> kl str) &&
    (Right i :: Either String Int) == (fromEitherCPS . EitherCPS) (\kl kr -> kr i)

-- main

cps_check = do {
    quickCheck prop_CPS; 
    quickCheck prop_tuple; 
    quickCheck prop_maybe;   
    quickCheck prop_either;
    putStrLn "+++ Done.";
}

